package com.googlecode.perfectable.eventable.routing;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.LinkedList;
import java.util.List;

public class Board<E> extends Channel<E> {
	private final List<E> elements = new LinkedList<>();

	protected Board() {
	}

	public static <X> Board<X> create() {
		return new Board<>();
	}

	@Override
	public void receive(E message) {
		checkNotNull(message);
		this.elements.add(message);
		super.receive(message);
	}

	@Override
	public void listen(Sink<E> sink) {
		checkNotNull(sink);
		for(E message : this.elements) {
			sink.receive(checkNotNull(message));
		}
		super.listen(sink);
	}

}
